package java8Com.chap3;

import vo.Apple;

import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * 方法引用
 */
public class methodReference {

    public static void test1() {
        Supplier<Apple> v = () -> new Apple();
        Apple apple = v.get();

        Supplier<Apple> supplier = Apple::new;
        Apple apple1 = supplier.get();

        System.out.println(apple1);
    }

    public static void test2() {
        Function<Integer, Apple> function = (weight) -> new Apple(weight);
        Apple apply = function.apply(10);

        Function<Integer, Apple> function1 = Apple::new;
        Apple apply1 = function1.apply(12);

        System.out.println(apply1.getWeight());
        System.out.println(apply.getWeight());
    }

    public static void test3() {
        BiFunction<String, Integer, Apple> function = (color, weight) -> new Apple(weight, color);
        Apple gree = function.apply("gree", 18);
        System.out.println("重量 ：" + gree.getWeight() + " 颜色：" + gree.getColor());

        //String和Integer参数放在Apple类的构造函数里
        BiFunction<String, Integer, Apple> function1=Apple::new;
        Apple gree1 = function1.apply("gree", 17);
    }


    public static void main(String[] args) {
        test3();
    }

}
